<?php
namespace app\shell;

use share\console\CConsole;
use share\console\CLIRunner;

class CDeamon  extends CLIRunner{

    const CHECK_RABBIT_CONSUMER_SIGN = "rabbitmq_consumer_rs";
    const RABBIT_CONSUMER_PATH = "/data/service/rabbitmq_consumer/rabbitmq_consumer.sh";

    public function check_rabbit_consumer_action(){   
        $checkCmd = "ps -ef | grep -v 'grep' | grep '".self::CHECK_RABBIT_CONSUMER_SIGN."'";
        $fp = popen($checkCmd,'r');
        $content = fread($fp,2048);
        fclose($fp);
        if(strpos($content,self::CHECK_RABBIT_CONSUMER_SIGN) === false){
            $shellCmd = "nohup ".self::RABBIT_CONSUMER_PATH."  > /dev/null 2>&1 &";
            $fp = popen($shellCmd,'r');
            fclose($fp);
            CConsole::print_line("consumer is started!");
        }
        else{
            CConsole::print_line("consumer is already running ...");
        }
    }

}